sequence = input("Введите скобочную последовательность: ") 
def is_valid_sequence(sequence): 
    matching_brackets = {')': '(', ']': '[', '}': '{', '>': '<'}
    a = [] 

    for bracket in sequence: 
        if bracket in "({[<": 
            a.append(bracket) 
        elif bracket in ")}]>": 
            if not a or a.pop() != matching_brackets[bracket]: 
                return False 
        else: 
            return False 
 
    return not a
 
print(is_valid_sequence(sequence))
